 //2288.价格减免
 //https://leetcode.cn/problems/apply-discount-to-prices
 class Solution {
 public:
     string discountPrices(string sentence, int discount) {
         int n = sentence.size();
         if (n <= 1) return sentence;
         int i = 0;
         string ret;
         ret.reserve(n * 2);
         long double dis = discount / 100.0;
         while (i < n)
         {
             if (sentence[i] == '$' && (i == 0 || sentence[i-1] == ' '))
             {
                 int k = i + 1;
                 bool dob = false;
                 while ((k < n && sentence[k] >= '0' && sentence[k] <= '9') || (sentence[k] == '.' && dob == false))
                 {
                     if (sentence[k] == '.') dob = true;
                     ++k;
                 }
                 if ((k == n || sentence[k] == ' ') && k > 0 && sentence[k - 1] >= '0' && sentence[k - 1] <= '9')
                 {
                     if (dis == 1.0) ret += "$0.00 ";
                     else
                     {
                         long double num = 0;
                         if (dob) num = stold(sentence.substr(i + 1, k - i + 1));
                         else num = stol(sentence.substr(i + 1, k - i + 1));
                         num -= (num*dis);
                         char str[40] = { 0 };
                         sprintf(str, "%.2llf ", num);
                         ret += '$';
                         ret += str;
                     }
                 }
                 else ret += sentence.substr(i, k - i + 1);
                 i = k;
             }
             else ret.push_back(sentence[i]);
             ++i;
         }
         if(ret.back() == ' ') ret.pop_back();
         return ret;
     }
 };